﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.DirectX.Direct3D;
using System.Threading;

namespace MediaCenter.Controls
{
    public class LCARS_ProgressBar : LCARS_Control
    {
        private int _SplitHeight;
        private int _MaximalValue;
        private int _Value;
        private int _EndWidth;

        public LCARS_ProgressBar()
        {
            _SplitHeight = 0;
            _MaximalValue = 100;
            _Value = 0;
            _EndWidth = 50;
        }

        public int SplitHeight
        {
            get
            {
                return _SplitHeight;
            }
            set
            {
                _SplitHeight = value;
                this.Refresh();
            }
        }

        public int MaximalValue
        {
            get
            {
                return _MaximalValue;
            }
            set
            {
                _MaximalValue = value;
                this.Refresh();
            }
        }

        public int Value
        {
            get
            {
                return _Value;
            }
            set
            {
                _Value = value;
                this.Refresh();
            }
        }

        public int EndWidth
        {
            get
            {
                return _EndWidth;
            }
            set
            {
                _EndWidth = value;
                this.Refresh();
            }
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if (this.DesignMode || this.PartmentForm.RenderMode == RenderMode.GDI)
            {
                double prozent = (double)_Value / (double)_MaximalValue;
                int quaderWH = this.Height / 3;
                int progresstop = (this.Height - this.Height / 4 * 2 - quaderWH) / 2 + this.Height / 4;
                int progresslength = this.Width - _EndWidth - quaderWH - progresstop;
                int progresslength1 = this.Width - _EndWidth - quaderWH - progresstop - progresstop / 2;
                int progressposs = System.Convert.ToInt32(progresslength1 * prozent);
                int progressheight = (this.Height / 2 - _SplitHeight);
                

                Graphics g = e.Graphics;
                Brush b = new SolidBrush(this.BackColor);
                Brush b1 = new SolidBrush(Color.Black);
                g.FillRectangle(b1, 0, progresstop, progresslength1 + quaderWH, quaderWH);
                g.FillRectangle(b, 0, 0, progresslength + progresstop, this.Height / 4);
                g.FillRectangle(b, 0, this.Height - this.Height / 4, progresslength + progresstop, this.Height / 4);
                g.FillRectangle(b, progresslength + progresstop, 0, this.Width - progresslength + progresstop, progressheight);
                g.FillRectangle(b, progresslength + progresstop, this.Height - progressheight, this.Width - progresslength + progresstop, progressheight);
                g.FillRectangle(b, progressposs, progresstop, quaderWH, quaderWH);
                
            }
        }
    }
}
